#ifndef NRF24L01_H_
#define NRF24L01_H_

#include "stm32f10x.h"

#define NRF24L01_RCC RCC_APB2Periph_GPIOA
#define NRF24L01_PORT GPIOA
#define NRF24L01_PIN_IRQ GPIO_Pin_8

#define NRF24L01_RCC2 RCC_APB2Periph_GPIOB
#define NRF24L01_PORT2 GPIOB
#define NRF24L01_PIN_CE GPIO_Pin_8
#define NRF24L01_PIN_CSN GPIO_Pin_12

#define NRF24L01_AW_SIZE 3

// 接收和发送状态
#define RX_DR 0x40
#define TX_DS 0x20
#define MAX_RT 0x10
#define TX_FULL 0x01

#define NRF24L01_READ_EMPTY 0x00
#define NRF24L01_READ_RX_PAYLOAD_LEN_ERROR 0x02

#define NRF24L01_SEND_ACK_PAYLOAD_LEN_ERROR 0x02
#define NRF24L01_SEND_MAX_RT 0x03
#define NRF24L01_SEND_TIMEOUT 0x0F
#define NRF24L01_SEND_UNKNOWN_ERROR 0x00

void nrf24l01_init(void);
void nrf24l01_setRxMode(void);
void nrf24l01_setTxMode(void);

uint8_t nrf24l01_readData(uint8_t *rxPayload, uint8_t *rxPayloadLen);
void nrf24l01_setAck(uint8_t *ackPayload, uint8_t ackPayloadLen);
void nrf24l01_sendData(uint8_t *txPayload, uint8_t txPayloadLen);
uint8_t nrf24l01_getAck(uint8_t *ackPayload, uint8_t *ackPayloadLen);

#endif /* NRF24L01_H_ */
